﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MyMainSite.Models;

namespace MyMainSite.Repositories
{
	public class ProjectScreenShotRepositoryImplemented : IProjectScreenShotRepository
	{
		#region Public Methods

		public bool AddScreenShot(int projectId, byte[] data)
		{
			if (projectId <= 0)
				throw new ArgumentException(String.Format("'{0}' is an invalid Project Id", projectId));
			if (data == null || data.Length <= 0)
				throw new ArgumentException("data");

			RichardsSiteEntities context = new RichardsSiteEntities();

			ProjectScreenShot ss = new ProjectScreenShot();
			ss.ProjectId = projectId;
			ss.Image = data;

			try
			{
				context.ProjectScreenShots.AddObject(ss);
				context.SaveChanges();
			}
			catch (Exception ex)
			{
				return false;
			}

			return true;
		}

		#endregion
	}
}